home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / editor / editor2 / txtrt305.lha / txtRotator305.rexx < prev   
OS/2 REXX Batch file  |  1996-11-12  |  10KB  |  393 lines

  1. /*--------------------------------------*/
  2. /* $VER: txtRotator V3.05 (12 Nov 1996) */
  3. /* ©1996 Michael Merkel                 */
  4. /*--------------------------------------*/
  5.  
  6. /*
  7.    how to use this:
  8.    ----------------
  9.  
  10.    1. draw a circle/ellipse/arc/pie with PageStream3
  11.       (please use PageStream3.1 BETA 3 or higher with this script
  12.        due to problems with rotated text objects in earlier versions)
  13.    2. select this object
  14.    3. start this script
  15.    4. press OK to see what happens
  16.  
  17.    notes:
  18.    ------
  19.  
  20.    * this script does NOT work with rotated objects!
  21.      (do it with the unrotated object first then group it and rotate all)
  22.    * it only works with "normal" circles/ellipses/arcs/pies
  23.    * text around ellipses sometimes look wierd - play with it
  24.  
  25.    comments to this program to:
  26.    ----------------------------
  27.       mmerkel@rummelplatz.uni-mannheim.de
  28.  
  29.    this is my first public arexx-script... don't blame me for that :-)
  30.  
  31.    IF YOU LIKE THIS SCRIPT PLEASE SEND ME A HARDCOPY OF THE
  32.    PAGESTREAM SCREEN WITH YOUR WORK ON IT!
  33.  
  34.    happy rotating...
  35.  
  36.    Michael Merkel
  37. */
  38.  
  39.  
  40. OPTIONS RESULTS
  41.  
  42. /* Make sure rexx support is opened */
  43. IF ~SHOW('L','rexxsupport.library') THEN
  44.    CALL ADDLIB('rexxsupport.library',0,-30)
  45. IF ~SHOW('L','softlogik:libs/slarexxsupport.library') THEN
  46.    CALL ADDLIB('softlogik:libs/slarexxsupport.library',0,-30)
  47. IF ~SHOW('L','rexxmathlib.library') THEN
  48.    CALL ADDLIB('rexxmathlib.library',0,-30)
  49. ADDRESS 'PAGESTREAM'
  50.  
  51. trversion = 'V3.05'
  52.  
  53. 'GETOBJECT TYPE 'typ
  54.  ret = RESULT
  55. if (typ ~= 7) | (ret = 10) then call DOERRORREQUESTER
  56.  
  57. defmeasure = GetDefaultMeasurementSystem()
  58.  
  59. 'GETELLIPSE POSITION koordinaten ANGLES winkel'
  60. id = result
  61.  
  62. typ = winkel.type
  63.  
  64. startw = 0
  65. endw = 360
  66. if winkel.type ~= 'ELLIPSE' then do
  67.     endw = (450 - p2d(winkel.begin)) // 360
  68.     startw = (450 - p2d(winkel.end)) // 360
  69.     if endw < startw then endw = endw + 360
  70. end
  71.  
  72. call ReadTXTRotatorPrefs
  73.  
  74. measure = 'pt'
  75. posifaktor = 1
  76. rifaktor = 1
  77. degree = '°'
  78. tf.0 = 'FALSE'
  79. tf.1 = 'TRUE'
  80.  
  81. mx = koordinaten.centerx
  82. my = koordinaten.centery
  83. rx = koordinaten.radiusx
  84. ry = koordinaten.radiusy
  85.  
  86. call DOREQUESTER
  87. if ergebnis = cancelhandler THEN do
  88.     ''defmeasure''
  89.     EXIT
  90. end
  91.  
  92. if tposi=1 then posifaktor = -1
  93. if tposi=2 then posifaktor = 0
  94.  
  95. endw = endw + 360*(xfaktor-1)
  96.  
  97. if richtung = 1 then do
  98.     rifaktor = -1
  99.     dummy = startw
  100.     startw = endw
  101.     endw = dummy
  102. end
  103.  
  104. call WriteTXTRotatorPrefs
  105.  
  106. size = p2d(textsize,measure)
  107. r    = radius
  108. mx   = mx
  109. my   = my
  110. rx   = rx
  111. ry   = ry
  112.  
  113. /* ---------------------------------------------------------------- */
  114.  
  115. 'REFRESH OFF'
  116.  
  117. 'CURRENTWINDOWPATH'
  118.  winname = RESULT
  119.  
  120. if (hidewin = 1) then 'HIDEWINDOW'
  121.  
  122. 'OPENBUSYREQUESTER MESSAGE "text is placed around 'typ'..." THERMOMETER ENABLED ABORT ENABLED TOTAL 'l' CURRENT 0'
  123.  BusyReq=result
  124.  
  125. highwinkel = -3.1415 * 0.5 + endw*3.1415/180
  126. lowwinkel  = -3.1415 * 0.5 + startw*3.1415/180
  127.  
  128. altrx = rx
  129. altry = ry
  130.  
  131. deltaradiusx = rx - (rx*icf)
  132. deltaradiusy = ry - (ry*icf)
  133.  
  134. deltaradiusrundx = deltaradiusx / xfaktor
  135. deltaradiusrundy = deltaradiusy / xfaktor
  136.  
  137. deltabuchstaben = l / xfaktor
  138.  
  139. deltaminusx = deltaradiusrundx / deltabuchstaben
  140. deltaminusy = deltaradiusrundy / deltabuchstaben
  141.  
  142. do num = 0 to l-1
  143.     character = SUBSTR(text,num+1,1)
  144.     CALL setbusy(num)
  145.  
  146.     'DRAWTEXTOBJ 'mx my' INFRONT'
  147.      textid = RESULT
  148.     'SELECTTEXT AT 'mx my' FRONTMOST'
  149.     'BEGINCOMMANDCAPTURE'
  150.      'SETTYPESIZE 'size
  151.      'SETTYPEWIDTH 100%'
  152.      'SETTRACKING NONE'
  153.      'SETLEADING RELATIVE 100%'
  154.      'SETPARAGRAPHSTYLE 'charstyle
  155.     'ENDCOMMANDCAPTURE'
  156.     'INSERT "'character'"'
  157.     'ROTATE 0'degree
  158.     'GETTEXTOBJ POSITION txtpos2 OBJECTID 'textid
  159.  
  160.     if icf ~= 1 then txtpos2 = SCALEOBJECT(txtpos2,textid,(rx/altrx))
  161.  
  162.     txtheight = txtpos2.bottom - txtpos2.top
  163.     txtwidth  = txtpos2.right - txtpos2.left
  164.  
  165.     if (l>1) then sinus = (highwinkel-lowwinkel) / (l-1) * num + lowwinkel
  166.     else          sinus = (highwinkel-lowwinkel) * num + lowwinkel
  167.  
  168.     dreh = sinus * 180 / 3.1415
  169.  
  170.     sinusresult   = sin(sinus)
  171.     cosinusresult = cos(sinus)
  172.  
  173.     nrx = rx + (txtheight/2)*posifaktor
  174.     nry = ry + (txtheight/2)*posifaktor
  175.  
  176.     xx2 = mx + cosinusresult * nrx
  177.     yy2 = my + sinusresult   * nry
  178.  
  179.     movx = (xx2-mx-(txtwidth/2))
  180.     movy = (yy2-my-(txtheight/2))
  181.  
  182.     'MOVE OFFSET 'movx movy' OBJECTID 'textid
  183.  
  184.     /* Berechnen des Buchstaben-Drehwinkels */
  185.  
  186.     x0 = cosinusresult * rx
  187.     y0 = sinusresult   * ry
  188.  
  189.     if y0 = 0 then
  190.     dreh = -3.1415 / 2
  191.     else do
  192.     dreh = (x0*ry*ry)/(y0*rx*rx)
  193.     dreh = atan(dreh)
  194.     end
  195.     dreh = 180 + dreh * 180 / 3.1415
  196.  
  197.     if (y0 * rifaktor) > 0 then
  198.     'ROTATE 'dreh degree
  199.     else
  200.     'ROTATE '180+dreh degree
  201.  
  202.     if SUBSTR(text,num+1,1)==' ' then 'DELETEOBJECT objectid 'textid
  203.  
  204.     rx = rx - deltaminusx
  205.     ry = ry - deltaminusy
  206. end
  207.  
  208. call CLEANUP(1)
  209.  
  210. DOREQUESTER:
  211.     l = 0
  212.     do while (l<1)
  213.     'ALLOCAREXXREQUESTER "text around 'typ trversion'©1996 Michael Merkel" 320 205'
  214.      reqhandle = RESULT
  215.     'ADDAREXXGADGET 'reqhandle' EXIT 10  185 70 LABEL "_Ok"'
  216.      okhandler = RESULT
  217.     'ADDAREXXGADGET 'reqhandle' EXIT 240 185 70 LABEL "_Cancel"'
  218.      cancelhandler = RESULT
  219.  
  220.     'ADDAREXXGADGET 'reqhandle' STRING 150 10 50 STRING "'startw'" LABEL "angles (°) start:"'
  221.      start_gadget = RESULT
  222.     'ADDAREXXGADGET 'reqhandle' STRING 250 10 50 STRING "'endw'" LABEL "end:"'
  223.      end_gadget = RESULT
  224.     'ADDAREXXGADGET 'reqhandle' STRING 86 30 50 STRING "'textsize'" LABEL "fontsize:"'
  225.      s_gadget = RESULT
  226.     'ADDAREXXGADGET 'reqhandle' STRING 200 30 115 STRING "'charstyle'" LABEL "style:"'
  227.      style_gadget = RESULT
  228.     'ADDAREXXGADGET 'reqhandle' STRING 10 60 305 STRING "'text'" LABEL "text to be placed:" LABELPOS "ABOVELEFT"'
  229.      t_gadget = RESULT
  230.  
  231.     'ALLOCAREXXLIST'
  232.      rexxlist = RESULT
  233.     'ADDAREXXLIST 'rexxlist' "above line"'
  234.     'ADDAREXXLIST 'rexxlist' "below line"'
  235.     'ADDAREXXLIST 'rexxlist' "on line"'
  236.     'ADDAREXXGADGET 'reqhandle' CYCLE 94 90 120 LABEL "place text"'
  237.      c_gadget = RESULT
  238.     'SETAREXXGADGET 'reqhandle c_gadget' LIST 'rexxlist' CURRENT 'tposi
  239.  
  240.     'ALLOCAREXXLIST'
  241.      rexxlist2 = RESULT
  242.     'ADDAREXXLIST 'rexxlist2' "clockwise"'
  243.     'ADDAREXXLIST 'rexxlist2' "counterclockwise"'
  244.     'ADDAREXXGADGET 'reqhandle' CYCLE 46 110 168 LABEL "text"'
  245.      ri_gadget = RESULT
  246.     'SETAREXXGADGET 'reqhandle ri_gadget' LIST 'rexxlist2' CURRENT 'richtung
  247.  
  248.     'ADDAREXXGADGET 'reqhandle' STRING 174 130 40 STRING "'icf'" LABEL "inner circle factor:"'
  249.      icf_gadget = RESULT
  250.  
  251.     'ADDAREXXGADGET 'reqhandle' STRING 126 145 40 STRING "'xfaktor'" LABEL "surrounding #:"'
  252.      xfaktor_gadget = RESULT
  253.  
  254.     'ADDAREXXGADGET 'reqhandle' CHECKBOX 10 165 10 CHECKED "'tf.hidewin'" LABEL "hide window while drawing (faster!)"'
  255.      hidewin_gadget = RESULT
  256.  
  257.     'DOAREXXREQUESTER 'reqhandle
  258.      ergebnis = RESULT
  259.  
  260.     'GETAREXXGADGET 'reqhandle start_gadget' STRING'
  261.      startw = RESULT
  262.     'GETAREXXGADGET 'reqhandle end_gadget' STRING'
  263.      endw = RESULT
  264.     'GETAREXXGADGET 'reqhandle s_gadget' STRING'
  265.      textsize = RESULT
  266.     'GETAREXXGADGET 'reqhandle style_gadget' STRING'
  267.      charstyle = RESULT
  268.     'GETAREXXGADGET 'reqhandle t_gadget' STRING'
  269.      text = RESULT
  270.      l = length(text)
  271.     'GETAREXXGADGET 'reqhandle c_gadget' CURRENT'
  272.      tposi = RESULT
  273.     'GETAREXXGADGET 'reqhandle ri_gadget' CURRENT'
  274.      richtung = RESULT
  275.     'GETAREXXGADGET 'reqhandle icf_gadget' STRING'
  276.      icf = RESULT
  277.     'GETAREXXGADGET 'reqhandle xfaktor_gadget' STRING'
  278.      xfaktor = RESULT
  279.     'GETAREXXGADGET 'reqhandle hidewin_gadget' CHECKED'
  280.      hidewin = RESULT
  281.     'FREEAREXXREQUESTER 'reqhandle
  282.     'FREAREXXLIST 'rexxlist
  283.     'FREAREXXLIST 'rexxlist2
  284.     end
  285. RETURN
  286.  
  287. DOERRORREQUESTER:
  288.     say 'Error: No circle/ellipse/arc/pie selected!'
  289.  
  290.     'ALLOCAREXXREQUESTER "Error!" 400 70'
  291.      reqhandle = RESULT
  292.     'ADDAREXXGADGET 'reqhandle' EXIT 165 50 70 LABEL "_Ok"'
  293.      dummy = RESULT
  294.  
  295.     'ADDAREXXGADGET 'reqhandle' TEXT 10 10 390 STRING "You did not chose an arc/ellipse/circle/pie!"'
  296.     'ADDAREXXGADGET 'reqhandle' TEXT 10 30 390 STRING "Select one and start me again!"'
  297.  
  298.     'DOAREXXREQUESTER 'reqhandle
  299.      dummy = RESULT
  300.  
  301.     'FREEAREXXREQUESTER 'reqhandle
  302.     exit
  303. RETURN
  304.  
  305. SCALEOBJECT:
  306.     ARG txtpos2,objectidnew,factor
  307.  
  308.     txt_x = txtpos2.left
  309.     txt_y = txtpos2.top
  310.     txt_xx = txtpos2.right
  311.     txt_yy  = txtpos2.bottom
  312.     txtheight = txt_yy - txt_y
  313.     txtwidth  = txt_xx - txt_x
  314.  
  315.     newtxt_x = txt_x + txtwidth * factor
  316.     newtxt_y = txt_y + txtheight * factor
  317.     'EDITTEXTOBJ POSITION 'txt_x txt_y newtxt_x newtxt_y' OBJECTID 'objectidnew
  318.     'GETTEXTOBJ POSITION txtpos2 OBJECTID 'textid
  319. RETURN txtpos2
  320.  
  321. SETBUSY:
  322.     parse arg value
  323.  
  324.     infonewtext = SUBSTR(text,1,value)||'['||substr(text,value+1,1)||']'||substr(text||' ',value+2)
  325.     infochar    = SUBSTR('...............'||infonewtext||'..............',value+1,30)
  326.  
  327.     'SETBUSYREQUESTER 'BusyReq' CURRENT 'value' MESSAGE "'infochar'"'
  328.     'GETBUSYREQUESTER 'BusyReq
  329.     if result=1 then call CLEANUP(1)
  330. RETURN
  331.  
  332. CLEANUP:
  333.     'CLOSEBUSYREQUESTER 'BusyReq
  334.     ''defmeasure''
  335.     if (hidewin = 1) then 'REVEALWINDOW WINDOW "'winname'"'
  336.     'REFRESH ON'
  337.     'REFRESHWINDOW'
  338. EXIT
  339.  
  340. ReadTXTRotatorPrefs:
  341.     ok = Open('Prefs','PageStream3:Scripts/txtRotator.prefs','R')
  342.     if ok = 1 then do
  343.     say 'reading old prefs...'
  344.     textsize = ReadLN('Prefs')
  345.     charstyle = ReadLN('Prefs')
  346.     text = ReadLN('Prefs')
  347.     tposi = ReadLN('Prefs')
  348.     richtung = ReadLN('Prefs')
  349.     icf = ReadLN('Prefs')
  350.     xfaktor = ReadLN('Prefs')
  351.     hidewin = ReadLN('Prefs')
  352.     Close('Prefs')
  353.     end
  354.     else do
  355.     say 'unable to read prefs -> default values'
  356.     textsize = '20pt'
  357.     charstyle = 'RoundText'
  358.     text = 'abcdefghijklmnopqrstuvwxyz0123456789 '
  359.     tposi = 0
  360.     richtung = 0
  361.     icf = 1
  362.     xfaktor = 1
  363.     hidewin = 0
  364.     end
  365. RETURN
  366.  
  367. WriteTXTRotatorPrefs:
  368.     ok = Open('Prefs','PageStream3:Scripts/txtRotator.prefs','W')
  369.     if ok = 1 then do
  370.     say 'writing prefs...'
  371.     WriteLN('Prefs',textsize)
  372.     WriteLN('Prefs',charstyle)
  373.     WriteLN('Prefs',text)
  374.     WriteLN('Prefs',tposi)
  375.     WriteLN('Prefs',richtung)
  376.     WriteLN('Prefs',icf)
  377.     WriteLN('Prefs',xfaktor)
  378.     WriteLN('Prefs',hidewin)
  379.     Close('Prefs')
  380.     end
  381.     else do
  382.     say 'error writing prefs file "txtRotator.prefs"'
  383.     end
  384. RETURN
  385.  
  386. GetDefaultMeasurementSystem:
  387.     PROCEDURE
  388.  
  389.     'GETMEASUREMENTS COORDINATE stemc RELATIVE rel TEXT tex FROM fro'
  390.     st = 'SETMEASUREMENTS COORDINATE 'stemc.horizontal stemc.vertical' RELATIVE 'rel' TEXT 'tex' FROM 'fro
  391.     'SETMEASUREMENTS COORDINATE POINTS SAMEAS RELATIVE SAMEAS TEXT POINTS FROM PAGE'
  392. RETURN st
  393.